home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / dte5_1.zip / HWHPXL.C < prev    next >
C/C++ Source or Header  |  1991-02-06  |  50KB  |  1,589 lines

  1. /*
  2.  * Written by Douglas Thomson (1989/1990)
  3.  *
  4.  * This source code is released into the public domain.
  5.  */
  6.  
  7. /*
  8.  * Name:    dte - Doug's Text Editor program - hardware dependent module
  9.  * Purpose: This file contains all the code that needs to be different on
  10.  *           different hardware.
  11.  * File:    hwhpxl.c (actually HWHPXLC due to naming restrictions)
  12.  * Author:  Douglas Thomson
  13.  * System:  This particular version is for the HP3000 running MPE/XL.
  14.  * Date:    October 10, 1989
  15.  * Notes:   This module has been kept as small as possible, to facilitate
  16.  *           porting between different systems.
  17.  *          This is a preliminary version, which does not support any
  18.  *           way to find out whether a character has been typed without
  19.  *           waiting for it. There seems to be no simple way to do this.
  20.  *           I tried using NOWAIT I/O on $STDIN, but it seems that a
  21.  *           pending read (even a NOWAIT read) prevents any further output
  22.  *           to the terminal!!!
  23.  *          Because of this, it is very important to use what HP call a
  24.  *           type ahead engine. This is supplied in a file called:
  25.  *              TYPE.DTS0000.TELESUP
  26.  *           and the required command is:
  27.  *              TYPE.DTS0000.TELESUP ON
  28.  *           which enables type ahead for all subsequent programs. HP
  29.  *           have some justification for not making this the default,
  30.  *           but I confess I could not follow their logic.
  31.  *          Without type ahead, "dte" loses keystrokes all over the place!
  32.  */
  33. #include "commonh"     /* dte types */
  34. #include "hwdeph"      /* prototypes for functions here */
  35. #include "utilsh"      /* for displaying messages etc */
  36. #include "versionh"    /* current version number */
  37. #include <mpe.h>       /* access to MPE intrinsics */
  38. #include <varargs.h>   /* for passing variable numbers of parameters */
  39. #include <fcntl.h>     /* for open flags */
  40.  
  41. /*
  42.  * prototypes for all functions in this file
  43.  */
  44. static void myputchar ARGS((char c));
  45. static void myputs ARGS((char *s));
  46. void error ARGS((int kind, ...));
  47. static void termset ARGS((char *name));
  48. void main ARGS((int argc, char *argv[]));
  49. static void hw_attr ARGS((char attr));
  50. static void att_stuff ARGS((void));
  51. void att_check ARGS((void));
  52. void hw_xygoto ARGS((void));
  53. int hw_clreol ARGS((void));
  54. int hw_linedel ARGS((int line));
  55. int hw_scroll_up ARGS((int top, int bottom));
  56. int hw_lineins ARGS((int line));
  57. int hw_scroll_down ARGS((int top, int bottom));
  58. int hw_c_avail ARGS((void));
  59. int hw_c_input ARGS((void));
  60. void hw_c_output ARGS((int c));
  61. void hw_terminate ARGS((void));
  62. void hw_initialize ARGS((void));
  63. void hw_move ARGS((text_ptr dest, text_ptr source, long number));
  64. int hw_backspace ARGS((void));
  65. int hw_c_insert ARGS((void));
  66. int hw_c_delete ARGS((void));
  67. int hw_rename ARGS((char *old, char *new));
  68. int hw_fattrib ARGS((char *name));
  69. int hw_set_fattrib ARGS((char *name, int attrib));
  70. int hw_unlink ARGS((char *name));
  71. int hw_printable ARGS((int c));
  72. int hw_load ARGS((char *name, text_ptr start, text_ptr limit, text_ptr *end));
  73. static int write_file ARGS((char *name, char *mode, text_ptr start,
  74.         text_ptr end));
  75. int hw_save ARGS((char *name, text_ptr start, text_ptr end));
  76. int hw_append ARGS((char *name, text_ptr start, text_ptr end));
  77. int hw_print ARGS((text_ptr start, text_ptr end));
  78. void hw_copy_path ARGS((char *old, char *name, char *new));
  79.  
  80. /*
  81.  * These pragmas provide access to system intrinsics necessary mainly
  82.  *  for direct keyboard input.
  83.  */
  84. #pragma intrinsic COMMAND MPE_COMMAND
  85. #pragma intrinsic FFILEINFO MPE_FFILEINFO
  86. #pragma intrinsic FCONTROL MPE_FCONTROL
  87. #pragma intrinsic FDEVICECONTROL MPE_FDEVICECONTROL
  88. #pragma intrinsic FREAD MPE_FREAD
  89. #pragma intrinsic FWRITE MPE_FWRITE
  90. #pragma intrinsic FRENAME MPE_FRENAME
  91. #pragma intrinsic HPCIPUTVAR MPE_PUTVAR
  92.  
  93. #define REVERSE 1       /* reverse video (or standout) attribute */
  94. #define HIGH 2          /* high intensity (or underline) attribute */
  95. #define NORMAL 3        /* normal video attribute */
  96.  
  97. /*
  98.  * The following variables store the appropriate escape sequences for
  99.  *  the current terminal type. This is not very elegant coding, although
  100.  *  the problem with global variables is at least restricted to just this
  101.  *  one source file.
  102.  * Eventually it would be nice to implement some equivalent to a UNIX
  103.  *  termcap file...
  104.  */
  105. static char *t_flash1;  /* start flash attribute */
  106. static char *t_flash0;  /* end flash attribute */
  107. static char *t_block1;  /* start block attribute */
  108. static char *t_block0;  /* end block attribute */
  109. static char *t_eol;     /* erase to end of line */
  110. static char *t_insline; /* insert line */
  111. static char *t_delline; /* delete line */
  112. static char *t_inschar; /* insert character */
  113. static char *t_delchar; /* delete character */
  114. static char *t_defwind; /* define scrollable window */
  115. static char *t_scrup;   /* scroll window up */
  116. static char *t_scrdown; /* scroll window down */
  117. static char *t_cp;      /* cursor positioning */
  118. static int   t_cpoff;   /* cursor positioning offset */
  119. static int   t_hptinit; /* set up HP (700/41) terminal function keys? */
  120.  
  121. /*
  122.  * Under MPE/XL, text files can either have variable length lines or fixed
  123.  *  length lines. For most purposes (such as program source files) using
  124.  *  variable length lines saves wasting space. However, MPE/XL insists that
  125.  *  job files have fixed length lines. Therefore, the editor must be able to
  126.  *  create either kind of file.
  127.  * This is achieved by checking the name of the executing program: DTE implies
  128.  *  variable length lines, DTEJ implies fixed length lines.
  129.  * The "g_job_file" variable is set TRUE if we are working with job files.
  130.  */
  131. int g_job_file;
  132.  
  133. /*
  134.  * the following variable determines the size of the memory buffer used. It
  135.  *  is set to something reasonable in main.
  136.  */
  137. static int g_space = 0;
  138.  
  139. /*
  140.  * Name:    myfflush
  141.  * Purpose: To flush any pending characters in the output buffer.
  142.  * Date:    September 3, 1990
  143.  */
  144. static void myfflush()
  145. {
  146.     fflush(stdout);
  147. }
  148.  
  149. /*
  150.  * Name:    myputchar
  151.  * Purpose: To output a single character to the display device.
  152.  * Date:    September 3, 1990
  153.  * Passed:  c:  the character to be output
  154.  */
  155. static void myputchar(c)
  156. char c;
  157. {
  158.     putc(c, stdout);
  159. }
  160.  
  161. /*
  162.  * Name:    myputs
  163.  * Purpose: To output a character string to the display device.
  164.  * Date:    November 6, 1989
  165.  * Passed:  s:  the character string to be output
  166.  */
  167. static void myputs(s)
  168. char *s;
  169. {
  170.     while (*s) {
  171.         myputchar(*s++);
  172.     }
  173. }
  174.  
  175. /*
  176.  * Name:    error
  177.  * Purpose: To report an error, and usually make the user type <ESC> before
  178.  *           continuing.
  179.  * Date:    October 10, 1989
  180.  * Passed:  kind:   an indication of how serious the error was:
  181.  *                      TEMP:    merely a message, do not wait for <ESC>
  182.  *                      DIAG:    merely a message, but make sure user sees it
  183.  *                      WARNING: error, but editor can continue after <ESC>
  184.  *                      FATAL:   abort the editor!
  185.  *          format: printf format string for any arguments that follow
  186.  *          ...:    arguments to be printed
  187.  * Notes:   This function should be system independent; that is the whole
  188.  *           point of the "stdarg" philosophy. However, two of the systems
  189.  *           I have used implemented "stdarg" incompatibly, and some older
  190.  *           systems may not support the "stdarg" macros at all...
  191.  */
  192. void error(kind, va_alist)
  193. int kind;
  194. va_dcl
  195. {
  196.     char *format;           /* printf format string for error message */
  197.     va_list argptr;         /* used to access various arguments */
  198.     char buff[MAX_COLS];    /* somewhere to store error before printing */
  199.     int c;                  /* character entered by user to continue */
  200.  
  201.     /*
  202.      * obtain the first two arguments
  203.      */
  204.     va_start(argptr);
  205.     format = va_arg(argptr, char *);
  206.  
  207.     /*
  208.      * tell the user what kind of an error it is
  209.      */
  210.     switch (kind) {
  211.     case FATAL:
  212.         strcpy(buff, "Fatal error: ");
  213.